<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>武神推演</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
    <form id="tuiyan_form">
        <label for="account">用户名:&nbsp;&nbsp;</label> <input name="account" id="account"/><br/>
        <label for="password">密&nbsp;&nbsp;码:&nbsp;&nbsp;&nbsp;</label> <input name="password" id="password" type="password"/><br/>
        <label for="zone">区&nbsp;&nbsp;服:&nbsp;&nbsp;&nbsp;</label> <input name="zone" id="zone"/><br/>
        <label for="player">角色名:&nbsp;&nbsp;</label> <input name="player" id="player"/><br/>
        <label for="book">自创秘籍:</label> <input name="book" id="book"/><br/>
        <label for="position">推演位置:</label>
        <select name="position" id="position">
            <option value="force" selected>内功</option>
            <option value="unarmed">拳脚</option>
            <option value="throwing">暗器</option>
            <option value="sword">剑法</option>
            <option value="blade">刀法</option>
            <option value="whip">鞭法</option>
            <option value="club">棍法</option>
            <option value="staff">杖法</option>
            <option value="dodge">轻功</option>
            <option value="parry">招架</option>
        </select><br/>
        <label for="">词条:&nbsp;&nbsp;&nbsp;&nbsp;</label><span id="attributes_span"></span><br/>
        <label for="">连续跳不中断:</label> <label for="continuation_True"><input name="continuation" id="continuation_True" type="radio" value="True"/>是</label>  <label for="continuation_False"><input name="continuation" id="continuation_False" type="radio" value="False" checked/>否</label><br/>
        <label for="total">总次数:&nbsp;&nbsp;</label> <input name="total" id="total"/><br/>
        <label for="step">步数:&nbsp;&nbsp;&nbsp;&nbsp;</label> <input name="step" id="step"/><br/>
        <label for="feiyiId">飞翼剑ID:&nbsp;&nbsp;</label> <input name="feiyiId" id="feiyiId"/><br/>
        <label for="">是否使用冰心丹:</label> <label for="haveBingxin_True"><input name="haveBingxin" id="haveBingxin_True" type="radio" value="True"/>是</label>  <label for="haveBingxin_False"><input name="haveBingxin" id="haveBingxin_False" type="radio" value="False" checked/>否</label><br/>
		<input type="button" value="提交" onclick="submitTuiyan()"/>
    </form>
	<div>
		角色名：<input id="player_look"> <input type="button" value="查看状态" onclick="look()"/>
		<div id="content"></div>
	</div>
    <script>
	    var baseUrl="http://1.15.134.70/server"
        $(function(){
            $.get(baseUrl+"/attributes",function(data){
			    var htmlText=""
				for (key in data){
				    htmlText=htmlText+'<label for="attributes_'+key+'"><input name="attributes" id="attributes_'+key+'" type="checkbox" value="'+key+'"/>'+key+'</label>  '
				}
				$("#attributes_span").html(htmlText)
			})
        });
		function submitTuiyan(){
			var fieldArray = $('#tuiyan_form').serializeArray();
			json=paserArrayToJson(fieldArray)
			console.log(json)
			
			if (json['account'] == ""){
				alert("账号不能为空")
				return
			}
			if (json['password'] == ""){
				alert("密码不能为空")
				return
			}
			if (json['zone'] == ""){
				alert("区服不能为空")
				return
			}
			if (json['player'] == ""){
				alert("角色名不能为空")
				return
			}
			if (json['book'] == ""){
				alert("秘籍不能为空")
				return
			}
			if (json['book'].endsWith("秘籍")){
				alert("不要秘籍两个字")
				return
			}
			if (json['position'] == ""){
				alert("推演位置不能为空")
				return
			}
			if (json.hasOwnProperty('attributes')&&json['attributes']!=""&&json['attributes'].split(",").length>5){
				alert("属性不能超过五个")
				return
			}
			if (json['continuation'] == ""){
				json['continuation']="False"
			}
			if (json['total'] == ""){
				alert("总次数不能为空且必须为数字，乱填出问题责任自负")
				return
			}
			if (json['step'] == ""&&json['continuation']=="False"){
				alert("连续跳不中断为否时，步数不能为空且必须为数字，乱填出问题责任自负")
				return
			}
			
			if (json['haveBingxin'] == ""){
				json['haveBingxin']="False"
			}
			
			var c;
			if (json['continuation']=="True"){
			    c="将不中断的连续跳"+json['total']+"次"
			}else{
			    c="将每"+json['step']+"下中断一次的跳"+json['total']+"次"
			}
			var a="";
			if (json.hasOwnProperty('attributes')&&json['attributes']!=""){
			    a=json['attributes']
			}
			var r=confirm("账号["+json['account']+"]下的["+json['zone']+"]区的角色["+json['player']+"] 要推演 ["+json['position']+"] 的["+a+"] 属性,"+c+", 是否确定")
			if (r==true){
			    var post=JSON.stringify(json);
				$.post(baseUrl, post, function(data){
				   $("#player_look").val(json['player'])
				   look()
				})
			}
		}
		function paserArrayToJson(array) {
            var result = {};
            for (var i = 0; i < array.length; i++) {
                var field = array[i];
                if (field.name in result) {
                    result[field.name] += ',' + field.value;
                } else {
                    result[field.name] = field.value;
                }
            }
            return result;
        }
                var id=0
		function look1(){
		    $.get(baseUrl+"/log?player="+$("#player_look").val(),function(data){
			    $("#content").append(data+"<br/>")
			    if(data.search("断开连接")!=-1||data=="无此用户"){
				self.clearInterval(id)
			    }
			})
		}
		function look() {
		    look1()
		    id=self.setInterval("look1()",10000)
        }
		
    </script>
</body>
</html>
